/**
 * @param {string} s
 * @param {number[]} distance
 * @return {boolean}
 */
var checkDistances = function (s, distance) {
  for (let i = 0; i < s.length; i++) {
    let fisrtIndex = s.indexOf(s[i])
    let lastIndex = s.lastIndexOf(s[i])
    if (
      distance[s[i].charCodeAt() - 'a'.charCodeAt()] !=
      lastIndex - fisrtIndex -1
    ) {
      return false
    }
  }
  return true
}

checkDistances(
  'abaccb',
  [1, 3, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
)
